/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgQuest
    {
        private readonly Dictionary<int, CfgQuest> _dataMap;
        private readonly List<CfgQuest> _dataList;

        /// <summary>
        /// 查询一个任务的父任务id
        /// </summary>
        public IReadOnlyDictionary<int, int> child2ParentMap { get; private set; }

        public TbCfgQuest(ByteBuf _buf)
        {
            //first read common data
            _TbCommonQuest _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonQuest(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgQuest>(size * 3 / 2);
            _dataList = new List<CfgQuest>(size);

            for (int i = 0; i < size; i++)
            {
                CfgQuest _v;
                _v = CfgQuest.DeserializeCfgQuest(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            { int __n0 = _buf.ReadSize(); var __f0 = new Dictionary<int, int> (__n0 * 3 / 2); child2ParentMap = __f0 ; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ) { int __k0; __k0 = _buf.ReadInt(); int __v0; __v0 = _buf.ReadInt(); __f0.Add(__k0, __v0); } }

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgQuest> DataMap => _dataMap;
        public IReadOnlyList<CfgQuest> DataList => _dataList;

        public CfgQuest Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgQuest] config not found,id:" + key.ToString());

            return null;
        }

        public CfgQuest GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "quest";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgQuest LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgQuest(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgQuest
    {
        private CfgQuest(ByteBuf _buf, _TbCommonQuest _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            Description = TableCenter.GetI18NText(_buf.ReadInt());
            Type = (QuestType)(_buf.ReadInt());
            SubType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; TypeParam = _commonData._field0[dataIndex]; }
            SortOrder = _buf.ReadInt();
            IsHide = _buf.ReadBool();
            AutoAcceptByCond = _buf.ReadBool();
            ManualAcceptable = _buf.ReadBool();
            ManualCondition = _buf.ReadInt();
            FunctionOpen = _buf.ReadInt();
            PreQuest = _buf.ReadInt();
            IsInherit = _buf.ReadBool();
            IsRepeat = _buf.ReadBool();
            ReceiveStory = _buf.ReadInt();
            TargetRegion = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; TargetShowEntity = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; TargetRangeSize = _commonData._field2[dataIndex]; }
            Source = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; AcceptGiveItem = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; CommitCostItem = _commonData._field4[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; CommitDeleteItem = _commonData._field5[dataIndex]; }
            CommitType = _buf.ReadInt();
            CommitStory = _buf.ReadInt();
            CommitedIsShow = _buf.ReadBool();
            { int dataIndex = _buf.ReadInt() - 1; Reward = _commonData._field6[dataIndex]; }
            GetPaypoint = _buf.ReadInt();
            TargetDescription = TableCenter.GetI18NText(_buf.ReadInt());
            TargetType = (QuestTargetType)(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; TargetParams = _commonData._field7[dataIndex]; }
            TargetNum = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; ChildQuests = _commonData._field8[dataIndex]; }
            ParentQuest = _buf.ReadInt();
            AutoAcceptCondId = _buf.ReadInt();
            InitNum = _buf.ReadInt();
            MaxPhase = _buf.ReadInt();
            ChangeStatus = _buf.ReadBool();
            IsItTraceable = _buf.ReadBool();
            AutoTrack = _buf.ReadBool();

            PostInit();
        }

        internal static CfgQuest DeserializeCfgQuest(ByteBuf _buf, _TbCommonQuest _commonData)
        {
            return new CfgQuest(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 任务名称文本
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 描述名称文本
        /// </summary>
        public string Description { get; private set; }
        /// <summary>
        /// 任务类型
        /// </summary>
        public QuestType Type { get; private set; }
        /// <summary>
        /// 任务子类型
        /// </summary>
        public int SubType { get; private set; }
        /// <summary>
        /// 任务类型
        /// </summary>
        public IReadOnlyList<int> TypeParam { get; private set; }
        /// <summary>
        /// 任务显示排序
        /// </summary>
        public int SortOrder { get; private set; }
        /// <summary>
        /// 是否隐藏
        /// </summary>
        public bool IsHide { get; private set; }
        /// <summary>
        /// 条件达成自动接取
        /// </summary>
        public bool AutoAcceptByCond { get; private set; }
        /// <summary>
        /// 是否允许手动接取
        /// </summary>
        public bool ManualAcceptable { get; private set; }
        /// <summary>
        /// 手动接取条件
        /// </summary>
        public int ManualCondition { get; private set; }
        /// <summary>
        /// 功能开启需求
        /// </summary>
        public int FunctionOpen { get; private set; }
        /// <summary>
        /// 前置任务要求
        /// </summary>
        public int PreQuest { get; private set; }
        /// <summary>
        /// 是否继承前置任务进度
        /// </summary>
        public bool IsInherit { get; private set; }
        /// <summary>
        /// 是否可重复完成
        /// </summary>
        public bool IsRepeat { get; private set; }
        /// <summary>
        /// 接取任务时的对话id
        /// </summary>
        public int ReceiveStory { get; private set; }
        /// <summary>
        /// 目标所在地区
        /// </summary>
        public int TargetRegion { get; private set; }
        /// <summary>
        /// 任务目标实体Id或者tag
        /// </summary>
        public IReadOnlyList<int> TargetShowEntity { get; private set; }
        /// <summary>
        /// 任务目标范围（半径）
        /// </summary>
        public IReadOnlyList<int> TargetRangeSize { get; private set; }
        /// <summary>
        /// 前往跳转（功能跳转表ID）
        /// </summary>
        public int Source { get; private set; }
        /// <summary>
        /// 接取任务时给予的道具
        /// </summary>
        public IReadOnlyList<int> AcceptGiveItem { get; private set; }
        /// <summary>
        /// 提交任务时消耗的道具
        /// </summary>
        public IReadOnlyList<int> CommitCostItem { get; private set; }
        /// <summary>
        /// 提交任务时清除的道具id（不填数量，只填道具ID）
        /// </summary>
        public IReadOnlyList<int> CommitDeleteItem { get; private set; }
        /// <summary>
        /// 任务提交方式(0手动，1自动）
        /// </summary>
        public int CommitType { get; private set; }
        /// <summary>
        /// 提交任务时的对话id
        /// </summary>
        public int CommitStory { get; private set; }
        /// <summary>
        /// 提交后是否需要在面板中显示（0-不显示；1-显示）
        /// </summary>
        public bool CommitedIsShow { get; private set; }
        /// <summary>
        /// 奖励
        /// </summary>
        public IReadOnlyList<int> Reward { get; private set; }
        /// <summary>
        /// 获得的付费货币
        /// </summary>
        public int GetPaypoint { get; private set; }
        /// <summary>
        /// 目标说明
        /// </summary>
        public string TargetDescription { get; private set; }
        /// <summary>
        /// 目标类型
        /// </summary>
        public QuestTargetType TargetType { get; private set; }
        /// <summary>
        /// 目标参数
        /// </summary>
        public IReadOnlyList<int> TargetParams { get; private set; }
        /// <summary>
        /// 目标数量
        /// </summary>
        public int TargetNum { get; private set; }
        /// <summary>
        /// 子任务列表
        /// </summary>
        public IReadOnlyList<int> ChildQuests { get; private set; }
        /// <summary>
        /// 所属主任务id
        /// </summary>
        public int ParentQuest { get; private set; }
        /// <summary>
        /// 自动接取条件，通常用于子任务
        /// </summary>
        public int AutoAcceptCondId { get; private set; }
        /// <summary>
        /// 初始进度
        /// </summary>
        public int InitNum { get; private set; }
        /// <summary>
        /// 开放的最大阶段
        /// </summary>
        public int MaxPhase { get; private set; }
        /// <summary>
        /// 是否会回滚状态，由完成-》未完成
        /// </summary>
        public bool ChangeStatus { get; private set; }
        /// <summary>
        /// 是否可追踪
        /// </summary>
        public bool IsItTraceable { get; private set; }
        /// <summary>
        /// 自动追踪（追踪栏空闲时，接取到新任务时，自动追踪新接取的任务
        /// </summary>
        public bool AutoTrack { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonQuest
    {

        internal IReadOnlyList<IReadOnlyList<int>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field5 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field6 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field7 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field8 { get; private set; }
        internal _TbCommonQuest(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field5 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field6 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field7 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field8 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
